<?php
$config = new RM_Config();
$currencySymbol = $config->getValue('rm_config_currency_symbol');
?>
<script type="text/javascript">
function DepositChange(checkbox){
    var action = 'removeJson';

    if (checkbox.checked) {
        action = 'useJson'
    }

    Ext.Ajax.request({
        url: RM.Common.AssembleURL({
            controller : 'Deposit',
            action: action
        })
    });
}

function UpdateDeposit(){

    var deposit_total = 0;
    for (var i = 0; i < rm_total.length; i++){
        deposit_total = deposit_total+rm_total[i].total;
    }
  
    Ext.Ajax.request({
        url: RM.Common.AssembleURL({
            controller : 'Deposit',
            action: 'selectJson',
            parameters : [{
                name : 'total',
                value : deposit_total
            }]
        }),
        success: function(responseObject) {
            document.getElementById("RM_deposit_checking").style.display = "none";
            var jsonObject = Ext.util.JSON.decode(responseObject.responseText);

            // show the deposit section
            if (jsonObject.deposit.enabled != "1") {
                return true;
            }

            document.getElementById("RM_deposit_option").style.display = "block";
            
            if (jsonObject.deposit.force == '1') {
                document.getElementById("RM_deposit_text_message").innerHTML = "<?php echo $this->_translate->_('User.Deposit.Main', 'DepositForceOption'); ?>";
            } else {
                document.getElementById("RM_deposit_checkbox").style.display = "block";
                document.getElementById("RM_deposit_checkhelper").style.display = "block";
                document.getElementById("RM_deposit_text_message").innerHTML = "<?php echo $this->_translate->_('User.Deposit.Main', 'DepositOption'); ?>";
            }

            // show value
            document.getElementById("RM_deposit_amount").innerHTML = "<?php echo $currencySymbol;?>" + jsonObject.deposit.value;
        },
        failure: function() {
             document.getElementById("RM_deposit_checking").style.display = "none";
        }
    });
}

window.onload=UpdateDeposit;

</script>
<td>
<div class="RM_reservation_summary_payment_selection_container">
    <div id="RM_deposit_checking">
        <?php echo $this->_translate->_('User.Deposit.Main', 'GettingDeposit'); ?>&nbsp;<img src='<?php echo RM_Environment::getConnector()->getRootURL(); ?>/RM/userdata/plugins/Deposit/views/user/scripts/Deposit/working.gif' border='0'>
    </div>
    <div id="RM_deposit_option" style="display:none;">
        <div class="RM_3columnlayout_col_left">
            <div id="RM_deposit_text">
                <span id="RM_deposit_text_message"></span>&nbsp;<span id="RM_deposit_amount"></span>
            </div>
        </div>
        <div class="RM_3columnlayout_col_center">
            <div id="RM_deposit_checkbox"  style="display:none;">
                <input type="checkbox" value="1" id="deposit_selection" onchange="DepositChange(this)" />
            </div>
        </div>
        <div class="RM_3columnlayout_col_right">
            <div id="RM_deposit_checkhelper"  style="display:none;">
                <?php echo $this->_translate->_('User.Deposit.Main', 'ChecktoSelect'); ?>
            </div>
        </div>
    </div>
</div>
</td>